/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.unibo.as.HeartsLogic;

import it.unibo.as.client.Table;

/**
 *
 * @author lilith
 */
public class TableGame
{   
    private final String strTableID;
    private final String strOwnerID;
    private GameLogic logic;
    private Table table;
    
    
    public TableGame(String strOwnerID, String strTableID, int nPlayerBots, int nTurn) 
    {
        table = new Table(strTableID,nPlayerBots,1);

        this.strOwnerID = strOwnerID;
        this.strTableID = strTableID;

        
        if(nPlayerBots > 3)
        {
            nPlayerBots = 3;
        }
        
        logic = new GameLogic(nPlayerBots, nTurn);
        
        Player p = new Player(strOwnerID);
        logic.addPlayer(p);
    }
    
    
    public boolean addPlayer(String strPlayerID)
    {
        boolean bRet = false;
        Player p = new Player(strPlayerID);
        bRet = logic.addPlayer(p);
        if(bRet){
            table.setActivePlayers(table.getActivePlayers() + 1);
        }
        return bRet;
    }

    
    public void removePlayer(String strPlayerID)
    {
        if(strPlayerID.compareTo(strOwnerID) == 0)
        {
            logic.gameDelete();
        }
        else
        {
            logic.removePlayer(strPlayerID);
        }
            
    }

    public Table getTableInfo() {
        return table;
    }


    
    public GameState getGameState(String strPlayerID, int lastUpdates)
    {
        GameState gs = logic.getGameState(strPlayerID);
        return gs;
    }
    
    public boolean nextTurn()
    {
        return logic.nextTurn();
    }
    
    public boolean playCard(String strPlayerID, int card)
    {
        return true;
    }

    public String getStrOwnerID() {
        return strOwnerID;
    }

    public String getStrTableID() {
        return strTableID;
    }

    public GameLogic getLogic() {
        return logic;
    }


    
    //changeCard
    
}
